package com.youyi.yyfilepickerlibrary.core.task;

import android.os.AsyncTask;
import com.youyi.yyfilepickerlibrary.core.model.EssFile;
import com.youyi.yyfilepickerlibrary.core.model.EssFileFilter;
import com.youyi.yyfilepickerlibrary.core.model.EssFileListCallBack;
import com.youyi.yyfilepickerlibrary.core.util.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class EssFileListTask extends AsyncTask<Void, Void, List<EssFile>> {
    private EssFileListCallBack callBack;
    private List<EssFile> mSelectedFileList;
    private int mSortType;
    private String queryPath;
    private String[] types;

    public EssFileListTask(List<EssFile> list, String str, String[] strArr, int i, EssFileListCallBack essFileListCallBack) {
        this.mSelectedFileList = list;
        this.queryPath = str;
        this.types = strArr;
        this.mSortType = i;
        this.callBack = essFileListCallBack;
    }

    /* access modifiers changed from: protected */
    public List<EssFile> doInBackground(Void... voidArr) {
        File[] listFiles = new File(this.queryPath).listFiles(new EssFileFilter(this.types));
        if (listFiles == null) {
            return new ArrayList();
        }
        List asList = Arrays.asList(listFiles);
        int i = this.mSortType;
        if (i == 0) {
            Collections.sort(asList, new FileUtils.SortByName());
        } else if (i == 1) {
            Collections.sort(asList, new FileUtils.SortByName());
            Collections.reverse(asList);
        } else if (i == 2) {
            Collections.sort(asList, new FileUtils.SortByTime());
        } else if (i == 3) {
            Collections.sort(asList, new FileUtils.SortByTime());
            Collections.reverse(asList);
        } else if (i == 4) {
            Collections.sort(asList, new FileUtils.SortBySize());
        } else if (i == 5) {
            Collections.sort(asList, new FileUtils.SortBySize());
            Collections.reverse(asList);
        } else if (i == 6) {
            Collections.sort(asList, new FileUtils.SortByExtension());
        } else if (i == 7) {
            Collections.sort(asList, new FileUtils.SortByExtension());
            Collections.reverse(asList);
        }
        List<EssFile> essFileList = EssFile.getEssFileList(asList);
        for (EssFile essFile : this.mSelectedFileList) {
            int i2 = 0;
            while (true) {
                if (i2 >= essFileList.size()) {
                    break;
                } else if (essFile.getAbsolutePath().equals(essFileList.get(i2).getAbsolutePath())) {
                    essFileList.get(i2).setChecked(true);
                    break;
                } else {
                    i2++;
                }
            }
        }
        return essFileList;
    }

    /* access modifiers changed from: protected */
    public void onPreExecute() {
        super.onPreExecute();
    }

    /* access modifiers changed from: protected */
    public void onPostExecute(List<EssFile> list) {
        EssFileListCallBack essFileListCallBack = this.callBack;
        if (essFileListCallBack != null) {
            essFileListCallBack.onFindFileList(this.queryPath, list);
        }
    }
}
